﻿using System;
using System.Collections.Generic;

namespace xfsale.lib
{
    public class SysProcParam
    {
        private string _name;
        private string _value;
        private string _direction;
        private string _type;
        private int _length;
        private int _position;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Value
        {
            get { return _value; }
            set { _value = value; }
        }

        public string Direction
        {
            get { return _direction; }
            set { _direction = value; }
        }

        public string Type
        {
            get { return _type; }
            set { _type = value; }
        }

        public int Length
        {
            get { return _length; }
            set { _length = value; }
        }

        public int Position
        {
            get { return _position; }
            set { _position = value; }
        }
    };

    public class SysProc
    {
        private string _name;
        private SortedList<string, SysProcParam> _params = new SortedList<string, SysProcParam>(StringComparer.OrdinalIgnoreCase);

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public SortedList<string, SysProcParam> Params
        {
            get { return _params; }
        }

        public void SetParam(string name, string value)
        {
            if (_params.ContainsKey(name))
            {
                if (!string.IsNullOrEmpty(value))
                {
                    _params[name].Value = value;
                }
            }
            else
            {
                Log.ThrowError("不存在存储过程参数 paramName={0}", name);
            }
        }

        public string GetParam(string name)
        {
            if (_params.ContainsKey(name))
            {
                return _params[name].Value;
            }
            else
            {
                Log.ThrowError("不存在存储过程参数 paramName={0}", name);
            }

            return null;
        }
    }
}
